﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Code.Repsitory
{
    public interface IBaseRepository<TEntity>
        //泛型约束
        where TEntity : class
    {
        /// <summary>
        /// 按主键删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        int Delete(int id);
        /// <summary>
        /// 按实体删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Delete(TEntity entity);
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Delete(List<TEntity> entity);
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="idList"></param>
        /// <returns></returns>
        int Delete(int[] idList);
        /// <summary>
        /// 按条件删除
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        int Delete(Expression<Func<TEntity, bool>> condition);
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="eneity"></param>
        /// <returns></returns>
        TEntity Insert(TEntity eneity);
        /// <summary>
        /// 查询Queryable
        /// </summary>
        /// <returns></returns>
        IQueryable<TEntity> Queryable();
        /// <summary>
        /// 查询第一个
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        TEntity QueryFirst(int id);
        /// <summary>
        /// 查询全部
        /// </summary>
        /// <returns></returns>
        List<TEntity> QueryAll();
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        List<TEntity> Query(Expression<Func<TEntity, bool>> condition);
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        TEntity Update(TEntity entity);
    }
}
